home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / unmount-all-images < prev   
Encoding:
Text File  |  2002-06-14  |  2.6 KB  |  123 lines

  1. #!/bin/sh
  2. # unmount-all-images
  3. # copyleft (c) 2000, joseph cheek, joseph@lycoris.com.  released under GPL.
  4. # unmount-all-images:
  5. # unmount all of the (cd, floppy, ramdisk) images from a build in the
  6. # current build directory that were mounted by the mount-all-images command.
  7. # ex: unmount-all-images
  8.  
  9. MNT="/opt/redmondlinux/builds/mnt"
  10.  
  11. if [ ! -f /tmp/initrd..new ]; then
  12.   echo /tmp/initrd..new does not exist\!
  13.   echo exiting . . .
  14.   exit 1
  15. fi
  16.  
  17.  
  18. # unmount initrd images from cd and install, copy back to appropriate
  19. # places
  20.  
  21. for a in cd install; do
  22.  
  23.   echo $a:
  24.   dir -l "$MNT"/$a/initrd.gz
  25.  
  26. # first create new ext2 filesystems
  27.  
  28.   cp /tmp/initrd.{,$a}.new
  29.  
  30. # mount the new filesystem, remove lost+found
  31.  
  32.   mount -o loop /tmp/initrd.$a.new "$MNT"/${a}_ramdisk.new/
  33.   rmdir "$MNT"/${a}_ramdisk.new/lost+found
  34.  
  35. # first use old initrd's
  36. # mount the new filesystem, remove files
  37.  
  38. # mount -o loop /tmp/initrd.$a.orig "$MNT"/${a}_ramdisk.new/
  39. # rm -rf "$MNT"/${a}_ramdisk.new/*
  40.  
  41. df -k "$MNT"/${a}_ramdisk
  42.  
  43. # copy over all files [gets rid of garbage laying around in ext2]
  44.   cp -a "$MNT"/${a}_ramdisk/.profile "$MNT"/${a}_ramdisk/* \
  45.     "$MNT"/${a}_ramdisk.new/
  46.  
  47.   echo after copy: 
  48.   df -k "$MNT"/${a}_ramdisk.new
  49.  
  50. # unmount the images
  51.   umount "$MNT"/${a}_ramdisk{,.new} || 
  52.     echo -e ${a}_ramdisk unmount failed\\a
  53.  
  54. # then write their contents back to the proper initrd.gz files
  55.  
  56. # comment next line to stop copy of initrd back to floppy images
  57.   gzip -9 -c /tmp/initrd.$a.new > "$MNT"/$a/initrd.gz
  58.   gzip -9 -c /tmp/initrd.$a.new > /tmp/initrd.$a.gz # second copy for testing
  59.   dir -l "$MNT"/$a/initrd.gz
  60.   df -k "$MNT"/$a
  61.   echo
  62.  
  63. # then remove the immutable bit [bug: assumes ext2 filesystem]
  64.   chattr -i /tmp/initrd.$a
  65.  
  66. # remove the files we used
  67.   rm /tmp/initrd.$a{,.gz,.orig}
  68.  
  69. done
  70.  
  71. for a in pcmcia; do
  72.  
  73. # first create new ext2 filesystems
  74.  
  75.   dd if=/dev/zero of=/tmp/$a.new bs=1k count=1440
  76.   mke2fs -q -m 0 -F -N 200 /tmp/$a.new
  77.  
  78. # mount the new filesystem, remove lost+found
  79.  
  80.   mount -o loop /tmp/$a.new "$MNT"/${a}.new/
  81.   rmdir "$MNT"/${a}.new/lost+found
  82.  
  83. # copy over all files [gets rid of garbage laying around in ext2]
  84.   cp -a "$MNT"/${a}/* "$MNT"/${a}.new/
  85.  
  86. # unmount the images
  87.   umount "$MNT"/${a}{,.new} || 
  88.   echo -e ${a} unmount failed\\a
  89.  
  90. # update original file
  91.   mv /tmp/${a}.144{,.orig}
  92.   mv /tmp/${a}.{new,144}
  93.   fup /tmp/${a}.144 floppy
  94.   mv /tmp/${a}.144{.orig,}
  95.  
  96. done
  97.  
  98.  
  99. # unmount ext2 files under loopback
  100.  
  101. umount "$MNT"/cd || 
  102.   echo -e cd unmount failed\\a
  103.  
  104. umount "$MNT"/install || 
  105.   echo -e install unmount failed\\a
  106.  
  107. umount "$MNT"/scsi ||
  108.   echo -e scsi unmount failed\\a
  109.  
  110.  
  111. # show mounts remaining
  112.  
  113. df -h
  114.